package com.csyf.manager.utils;

import lombok.extern.slf4j.Slf4j;

import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;

/**
 * 发送短信
 * 用 户 ID：195693
 * 子账户admin
 * 密 码：709225
 */
@Slf4j
public class SmsHelper {

    public static String sendMsg(String phone, String randomCode, String money) throws UnsupportedEncodingException {
        String url = "http://113.106.16.55:8080/GateWay/Services.asmx/DirectSend?";
        HashMap<String, String> map = new HashMap<>();

        String smsMsg = "【cspay】您将要代付" + money + "元，本次的验证码为：" + randomCode + "，有效期为10分钟。如非本人操作，请您忽略该信息。";
        String Content = java.net.URLEncoder.encode(smsMsg, "UTF-8");
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = new Date();

        map.put("UserID", "195693");
        map.put("Account", "admin");
        map.put("Password", "709225");
        map.put("Phones", phone);
        map.put("SendType", "1");
        map.put("SendTime", "");
        map.put("PostFixNumber", "");
        map.put("Content", Content);

        String smsResult = HttpHelper.doPostForm(url, map);
        //解析XMl内容
        String xmlContent = XmlParseHelper.getXmlContent(smsResult, "<RetCode>", "</RetCode>", 9);

        log.info("[{}]您本次的验证码为：{}，短信结果：{}", df.format(date), randomCode, xmlContent);
        return randomCode;
    }


    public static String sendlogMsg(String phone, String randomCode) throws UnsupportedEncodingException {
        String url = "http://47.92.152.3:8080/GateWay/Services.asmx/DirectSend?";
        HashMap<String, String> map = new HashMap<>();

        String smsMsg = "【ecpay】您将登录系统，本次的验证码为：" + randomCode + "，有效期为10分钟。如非本人操作，请您忽略该信息。";
        String Content = java.net.URLEncoder.encode(smsMsg, "UTF-8");
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = new Date();

        map.put("UserID", "195693");
        map.put("Account", "admin");
        map.put("Password", "709225");
        map.put("Phones", phone);
        map.put("SendType", "1");
        map.put("SendTime", "");
        map.put("PostFixNumber", "");
        map.put("Content", Content);

        String smsResult = HttpHelper.doPostForm(url, map);
        //解析XMl内容
        String xmlContent = XmlParseHelper.getXmlContent(smsResult, "<RetCode>", "</RetCode>", 9);

        log.info("[{}]您本次的验证码为：{}，短信结果：{}", df.format(date), randomCode, xmlContent);
        return randomCode;
    }

}
